package com.online.usermanagesystem.utils;

import java.util.HashMap;
import java.util.Map;

public class ResultUtil {

    public static DefaultResult OK = new DefaultResult(200, "OK");
    public static DefaultResult BAD_REQUEST = new DefaultResult(400, "Bad request");
    public static DefaultResult UNAUTHORIZED = new DefaultResult(401, "Unauthorized");
    public static DefaultResult FORBIDDEN = new DefaultResult(403, "Forbidden");
    public static DefaultResult NOT_FOUND = new DefaultResult(404, "Not found");
    public static DefaultResult NOT_Empty = new DefaultResult(604, "Not empty");
    public static DefaultResult CONFLICT = new DefaultResult(409, "Conflict");
    public static DefaultResult INTERNAL_SERVER_ERROR = new DefaultResult(500, "Internal server error");

    public static boolean isSuccess(Object object) {

        if (null == object) {
            return false;
        }

        if (DefaultResult.class.isAssignableFrom(object.getClass())) {
            return OK == object;
        }

        return true;
    }

    public static Object returnNull(Object object, Object defaultResult) {
        if (null == object) {
            return defaultResult;
        }

        return object;
    }

    public static Object returnKV(String key, Object value) {
        Map map = new HashMap();
        map.put(key, value);
        return map;
    }
}
